<? include ("../init.php") ?>
<?
  // ---------- UPLOADS Image ----------
  $handle = new Upload($_FILES['image']);
  
  if($handle->file_src_name != '')
  {
    if ($handle->uploaded)
    {
      if($handle->image_src_x>559){
        $handle->image_resize = true;
        $handle->image_x = 559;
        $handle->image_ratio_y = true;
      }
      
      $handle->Process(APPPATH.'/images/promotions');
      
      if ($handle->processed)
      {
         $sql = "UPDATE hs_promotion SET p_img='$handle->file_dst_name' WHERE p_id=1";
         if(!mysql_query($sql))
         {
              $data_add[1] = "Can\'t upload image file, please check again or contact the webmaster.";
              unlink(APPPATH."/images/promotions/".$handle->file_dst_name);
         }
         else
         {
          if(isset($_POST['oldimg']) AND $_POST['oldimg']!=''){
            unlink(APPPATH."/images/promotions/".$_POST['oldimg']);
          }
          $data_add[1] = "444444444444";
         }
      }
      else
      {
        $data_add[1] = "Can\'t upload image file, please check again or contact the webmaster.";
      }
      
      $handle->clean();
    }
    else
    {
        $data_add[1] = "Can\'t upload image file, please check again or contact the webmaster.";
    }
    
    $handle = new Upload($_FILES['banner']);
    if($handle->file_src_name != '')
    {
      if ($handle->uploaded)
      {
        if($handle->image_src_x!=243){
          $handle->image_resize = true;
          $handle->image_x = 243;
          $handle->image_ratio_y = true;
        }
        
        $handle->Process(APPPATH.'/images/promotions');
        
        if ($handle->processed)
        {
           $sql = "UPDATE hs_promotion SET p_banner='$handle->file_dst_name' WHERE p_id=1";
           if(!mysql_query($sql))
           {
                $data_add[1] = "Can\'t upload image file, please check again or contact the webmaster.";
                unlink(APPPATH."/images/promotions/".$handle->file_dst_name);
           }
           else
           {
            if(isset($_POST['oldimg']) AND $_POST['oldimg']!=''){
              unlink(APPPATH."/images/promotions/".$_POST['oldimg']);
            }
            $data_add[1] = "444444444444";
           }
        }
        else
        {
          $data_add[1] = "Can\'t upload image file, please check again or contact the webmaster.";
        }
        
        $handle->clean();
      }
      else
      {
          $data_add[1] = "Can\'t upload image file, please check again or contact the webmaster.";
      }
    }
    
  }else{
    $data_add[1] = "ssssss";
  }
    
  $sql = 'UPDATE hs_promotion SET p_active="'.$_POST['p_active'].'" WHERE p_id=1';
  $result = mysql_query($sql);
  
  //var_dump($data_add);
  header("Location:index.php");
?>